﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using System.Reflection;

namespace SharePointSiteConfigurator
{
    public class ListViewWebPartItem
    {
        public string Title { get; set; }
        public string TitleUrl { get; set; }
        public string ListName { get; set; }
        public string ViewName { get; set; }
        public string ZoneID { get; set; }
        public string ZoneIndex { get; set; }
        public string ToolbarType { get; set; }
        public string AllowMinimize { get; set; }
        public string AllowClose { get; set; }
        public string AllowHide { get; set; }
        public string AllowZoneChange { get; set; }
        public string AllowConnect { get; set; }
        public string AllowEdit { get; set; }

#if SP2010
        private static TraceLogger2010 mtr;
#else
        private static TraceLogger mtr;
#endif

        public ListViewWebPartItem(IEnumerable<XAttribute> attributes)
        {

            if (attributes == null) throw new ArgumentNullException("properties", "Cannot be null");
            foreach (XAttribute att in attributes)
            {
                try
                {
                    this.GetType().GetProperty(att.Name.ToString()).SetValue(this, att.Value, null);
                }
                catch (Exception ex)
                {
                    if (!(att.Name.ToString() == "FileName"))
                    {
#if SP2010
                        mtr = new TraceLogger2010(); // TraceLogger2010.Instance;
#else
            mtr = TraceLogger.Instance;
#endif
                        mtr.TraceVerboseMessage(string.Format("ListViewWebpart unable to set property: " + att.Name.ToString() + " with value: " + att.Value + " Error message: " + ex.ToString()));
                    }
                }
            }

        }
    }
}
